package util;

import android.graphics.Bitmap;
import android.graphics.Matrix;

/** Class containing some utility functions that may be used by any other class
 * 
 * @author Bruno Zumba (22/09/2011)
 *
 */
public class Util {
	
	//The type of the messages
	public static final int CONNECT = 0;
	public static final int DISCONNECT = 1;
	public static final int ENTITY_REDEFINITION = 2;
	public static final int ENTITY_UPDATE = 3;
	public static final int GAME_STATE = 4;
	public static final int ACK = 5;
	
	//The action the types COMM_MANAGEMENT, ENTITY_UPDATE and GAME_STATE demand
	public static final int CREATE = 0;
	public static final int SELL = 1;
	public static final int UPGRADE = 2;
	public static final int START = 3;
	public static final int WIN = 4;
	public static final int LOSE = 5;
	public static final int ERROR = 6;
	
	//The type of the turret created by the action CREATE
	public static final int TURRET1 = 1;
	public static final int TURRET2 = 2;
	
	/** Resize a bitmap image
	 * 
	 * @param bm The bitmap that must be resized
	 * @param newWidth New width of the bitmap
	 * @param newHeight New height of the bitmap
	 * @return The resized bitmap image
	 */
	public static Bitmap resizeBitmap(Bitmap bm, double newWidth, double newHeight) {
		int width = bm.getWidth();
		int height = bm.getHeight();
		
		float scaleWidth = ((float) newWidth) / width;
		float scaleHeight = ((float) newHeight) / height;
		
		// create a matrix for the manipulation
		Matrix matrix = new Matrix();
		
		// resize the bit map
		matrix.postScale(scaleWidth, scaleHeight);
		
		// recreate the new Bitmap
		Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);

		return resizedBitmap;
	
	}
	
	
	
	
	//The status are
	public static final int POWER = 0;
	public static final int FIRE_SPEED = 1;
	public static final int REACH = 2;
	public static final int COST = 3;
	
	/*Turret 1 status
	 * 					Level 1		Level 2		Level 3
	 * Power				10			20			30
	 * Fire Speed			10			20			30
	 * Reach				10			20			30
	 * Cost					100			200			300			
	 */
	
	public static float[][] turret1 = new float[4][4];
	public static float[][] turret2 = new float[4][4];
	
	public static void populateTurrets(){
		turret1[POWER][1] = 3; turret1[POWER][2] = 3; turret1[POWER][3] = 4; 
		turret1[FIRE_SPEED][1] = 1; turret1[FIRE_SPEED][2] = 2; turret1[FIRE_SPEED][3] = (float) 2.5;
		turret1[REACH][1] = 2; turret1[REACH][2] = 2; turret1[REACH][3] = 3;
		turret1[COST][1] = 250; turret1[COST][2] = 150; turret1[COST][3] = 400;
		

		turret2[POWER][1] = 5; turret2[POWER][2] = 5; turret2[POWER][3] = 8; 
		turret2[FIRE_SPEED][1] = 1; turret2[FIRE_SPEED][2] = 1; turret2[FIRE_SPEED][3] = (float) 1.5;
		turret2[REACH][1] = 1; turret2[REACH][2] = 2; turret2[REACH][3] = 2;
		turret2[COST][1] = 300; turret2[COST][2] = 300; turret2[COST][3] = 500;
	}

	public static float getTurret1Status(int status, int level){
		return turret1[status][level];
	}
	public static float getTurret2Status(int status, int level){
		return turret2[status][level];
	}

}
